﻿using System;
using System.Data;
using System.Text;
using MySql.Data.MySqlClient;
using BangleCMS.DBUtility;//Please add references
namespace BangleCMS.DAL
{
	/// <summary>
	/// 数据访问类:view_rolemenu_listDAL
	/// </summary>
	public partial class view_rolemenu_listDAL
	{
		public view_rolemenu_listDAL()
		{}
		#region  Method



		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BangleCMS.Model.view_rolemenu_list model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into view_rolemenu_list(");
			strSql.Append("RoleMenuId,RoleId,MenuId,MenuCode,MenuName,OrderNo,ModularId,href,Valid)");
			strSql.Append(" values (");
			strSql.Append("@RoleMenuId,@RoleId,@MenuId,@MenuCode,@MenuName,@OrderNo,@ModularId,@href,@Valid)");
			MySqlParameter[] parameters = {
					new MySqlParameter("@RoleMenuId", MySqlDbType.Int32,11),
					new MySqlParameter("@RoleId", MySqlDbType.Int32,11),
					new MySqlParameter("@MenuId", MySqlDbType.Int32,11),
					new MySqlParameter("@MenuCode", MySqlDbType.VarChar,50),
					new MySqlParameter("@MenuName", MySqlDbType.VarChar,100),
					new MySqlParameter("@OrderNo", MySqlDbType.Int32,11),
					new MySqlParameter("@ModularId", MySqlDbType.Int32,11),
					new MySqlParameter("@href", MySqlDbType.VarChar,200),
					new MySqlParameter("@Valid", MySqlDbType.Int32,21)};
			parameters[0].Value = model.RoleMenuId;
			parameters[1].Value = model.RoleId;
			parameters[2].Value = model.MenuId;
			parameters[3].Value = model.MenuCode;
			parameters[4].Value = model.MenuName;
			parameters[5].Value = model.OrderNo;
			parameters[6].Value = model.ModularId;
			parameters[7].Value = model.href;
			parameters[8].Value = model.Valid;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BangleCMS.Model.view_rolemenu_list model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update view_rolemenu_list set ");
			strSql.Append("RoleMenuId=@RoleMenuId,");
			strSql.Append("RoleId=@RoleId,");
			strSql.Append("MenuId=@MenuId,");
			strSql.Append("MenuCode=@MenuCode,");
			strSql.Append("MenuName=@MenuName,");
			strSql.Append("OrderNo=@OrderNo,");
			strSql.Append("ModularId=@ModularId,");
			strSql.Append("href=@href,");
			strSql.Append("Valid=@Valid");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
					new MySqlParameter("@RoleMenuId", MySqlDbType.Int32,11),
					new MySqlParameter("@RoleId", MySqlDbType.Int32,11),
					new MySqlParameter("@MenuId", MySqlDbType.Int32,11),
					new MySqlParameter("@MenuCode", MySqlDbType.VarChar,50),
					new MySqlParameter("@MenuName", MySqlDbType.VarChar,100),
					new MySqlParameter("@OrderNo", MySqlDbType.Int32,11),
					new MySqlParameter("@ModularId", MySqlDbType.Int32,11),
					new MySqlParameter("@href", MySqlDbType.VarChar,200),
					new MySqlParameter("@Valid", MySqlDbType.Int32,21)};
			parameters[0].Value = model.RoleMenuId;
			parameters[1].Value = model.RoleId;
			parameters[2].Value = model.MenuId;
			parameters[3].Value = model.MenuCode;
			parameters[4].Value = model.MenuName;
			parameters[5].Value = model.OrderNo;
			parameters[6].Value = model.ModularId;
			parameters[7].Value = model.href;
			parameters[8].Value = model.Valid;

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from view_rolemenu_list ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			int rows=DbHelperMySQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BangleCMS.Model.view_rolemenu_list GetModel()
		{
			//该表无主键信息，请自定义主键/条件字段
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RoleMenuId,RoleId,MenuId,MenuCode,MenuName,OrderNo,ModularId,href,Valid from view_rolemenu_list ");
			strSql.Append(" where ");
			MySqlParameter[] parameters = {
			};

			BangleCMS.Model.view_rolemenu_list model=new BangleCMS.Model.view_rolemenu_list();
			DataSet ds=DbHelperMySQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["RoleMenuId"]!=null && ds.Tables[0].Rows[0]["RoleMenuId"].ToString()!="")
				{
					model.RoleMenuId=int.Parse(ds.Tables[0].Rows[0]["RoleMenuId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["RoleId"]!=null && ds.Tables[0].Rows[0]["RoleId"].ToString()!="")
				{
					model.RoleId=int.Parse(ds.Tables[0].Rows[0]["RoleId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MenuId"]!=null && ds.Tables[0].Rows[0]["MenuId"].ToString()!="")
				{
					model.MenuId=int.Parse(ds.Tables[0].Rows[0]["MenuId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["MenuCode"]!=null && ds.Tables[0].Rows[0]["MenuCode"].ToString()!="")
				{
					model.MenuCode=ds.Tables[0].Rows[0]["MenuCode"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MenuName"]!=null && ds.Tables[0].Rows[0]["MenuName"].ToString()!="")
				{
					model.MenuName=ds.Tables[0].Rows[0]["MenuName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["OrderNo"]!=null && ds.Tables[0].Rows[0]["OrderNo"].ToString()!="")
				{
					model.OrderNo=int.Parse(ds.Tables[0].Rows[0]["OrderNo"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ModularId"]!=null && ds.Tables[0].Rows[0]["ModularId"].ToString()!="")
				{
					model.ModularId=int.Parse(ds.Tables[0].Rows[0]["ModularId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["href"]!=null && ds.Tables[0].Rows[0]["href"].ToString()!="")
				{
					model.href=ds.Tables[0].Rows[0]["href"].ToString();
				}
				if(ds.Tables[0].Rows[0]["Valid"]!=null && ds.Tables[0].Rows[0]["Valid"].ToString()!="")
				{
					model.Valid=long.Parse(ds.Tables[0].Rows[0]["Valid"].ToString());
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RoleMenuId,RoleId,MenuId,MenuCode,MenuName,OrderNo,ModularId,href,Valid ");
			strSql.Append(" FROM view_rolemenu_list ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM view_rolemenu_list ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.UserId desc");
			}
			strSql.Append(")AS Row, T.*  from view_rolemenu_list T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperMySQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			MySqlParameter[] parameters = {
					new MySqlParameter("@tblName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@fldName", MySqlDbType.VarChar, 255),
					new MySqlParameter("@PageSize", MySqlDbType.Int32),
					new MySqlParameter("@PageIndex", MySqlDbType.Int32),
					new MySqlParameter("@IsReCount", MySqlDbType.Bit),
					new MySqlParameter("@OrderType", MySqlDbType.Bit),
					new MySqlParameter("@strWhere", MySqlDbType.VarChar,1000),
					};
			parameters[0].Value = "view_rolemenu_list";
			parameters[1].Value = "UserId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperMySQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

